<template>
  <div>
    <MyHeader title="购物车案例" bgc="skyblue" color="deeppink"></MyHeader>
    <div class="main">
      <!--  遍历数据 将对象goods父传子 传给MyGoods组件 -->
      <MyGoods v-for="item in list" :key="item.id" :goods="item"></MyGoods>
    </div>
    <MyFooter :list="list"></MyFooter>
  </div>
</template>

<script>
import MyHeader from './components/MyHeader'
import MyGoods from './components/MyGoods'
import MyFooter from './components/MyFooter'
export default {
  components: {
    MyHeader,
    MyGoods,
    MyFooter
  },
  data() {
    return {
      //创建一个空数组，
      list: [],
    }
  },
  // 页面更新数据的时候利用axios 获取接口数据
  created() {
    this.$axios({
      url: '/api/cart',
      method: 'GET'
    }).then(res => {
      console.log(res)
      this.list = res.data.list
    })
  },
}
</script>

<style>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>